package niumao.minecraft.uhc.listener;

import niumao.minecraft.uhc.Util;
import org.bukkit.ChatColor;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.Damageable;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;

public class miner implements Listener {
    @EventHandler
    public void on(BlockBreakEvent event) {
        Player player = event.getPlayer();
        ItemStack item = player.getInventory().getItemInMainHand();
        ItemMeta itemMeta = item.getItemMeta();
        Damageable itemDamage = (Damageable) item.getItemMeta();
        if (itemDamage == null || itemMeta == null) return;
        if (itemMeta.getDisplayName().equals(Util.getStr("Miner"))) {
            if (itemDamage.getDamage() == 0) return;
            if (itemDamage.getDamage() % 100 == 0)
                player.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, 5 * 20, 0), true);
            if (itemDamage.getDamage() % 250 == 0) {
                int i = itemDamage.getDamage() / 250;
                itemMeta.addEnchant(Enchantment.DAMAGE_ALL, i, true);
                itemMeta.addEnchant(Enchantment.DIG_SPEED, i, true);
                item.setItemMeta(itemMeta);
            }
        }
    }
}
